package com.someclip.component.controlls
{
	import com.someclip.component.core.Component;
	import com.someclip.component.interfaces.ILabel;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;

	/**
	 * ...
	 * @author ...
	 */
	public class Label extends Component implements ILabel
	{
		private var _fontSize:uint=14;
		private var _fontWeight:Boolean=false;
		private var _fontColor:uint=0x000000;
		private var _text:String='Label';
		private var _textField:TextField;
		private var _textFormat:TextFormat;
		private var _textAlign:String="left";
		private var _selectAble:Boolean=true;
		private var _type:String=TextFieldType.DYNAMIC;
		private var _displayAsPassword:Boolean;

		public function Label()
		{
			this.width=100;
			this.height=20;
			this.useMask=false;
			_textField=new TextField();
			_textField.wordWrap=false;
			_textField.multiline=false;
			_textField.type=_type;
			addChild(_textField);
			_textFormat=new TextFormat();
			updateTextField();
		}

		private function updateTextField():void
		{
			_textField.width=this.width;
			_textField.text=_text;
			_textField.type=_type;
			_textField.selectable=_selectAble;
			_textField.displayAsPassword=_displayAsPassword;
			_textFormat.align=_textAlign;
			_textFormat.color=_fontColor;
			_textFormat.bold=_fontWeight;
			_textFormat.size=_fontSize;
			_textField.setTextFormat(_textFormat);
			_textField.height=_textField.textHeight + 4;
		}

		override public function set width(value:Number):void
		{
			super.width=value;
			if (_textField)
			{
				_textField.width=this.width;
			}
		}

		override public function set height(value:Number):void
		{
			super.height=value;
			if (_textField)
			{
				_textField.height=this.height;
			}
		}

		/**
		 * 获取文本内容
		 * @return
		 *
		 */
		public function get text():String
		{
			return _textField.text;
		}

		/**
		 * 设置文本内容
		 * @param value 字符串
		 *
		 */
		public function set text(value:String):void
		{
			_text=value;
			updateTextField();
		}



		/**
		 * 获取字体大小
		 * @return
		 *
		 */
		public function get fontSize():uint
		{
			return _fontSize;
		}

		/**
		 * 设置字体大小
		 * @param value
		 *
		 */
		public function set fontSize(value:uint):void
		{
			_fontSize=value;
			updateTextField();
		}

		/**
		 * 获取字体加粗
		 * @return 布尔值
		 *
		 */
		public function get fontWeight():Boolean
		{
			return _fontWeight;
		}

		/**
		 * 设置字体加粗
		 * @param value Boolean
		 *
		 */
		public function set fontWeight(value:Boolean):void
		{
			_fontWeight=value;
			updateTextField();
		}

		/**
		 * 获取字体颜色
		 * @return
		 *
		 */
		public function get fontColor():uint
		{
			return _fontColor;
		}

		/**
		 * 设置字体颜色
		 * @param value
		 *
		 */
		public function set fontColor(value:uint):void
		{
			_fontColor=value;
			updateTextField();
		}

		/**
		 * 获取文本对齐方式
		 * @return
		 *
		 */
		public function get textAlign():String
		{
			return _textAlign;
		}

		/**
		 * 设置文本对齐方式
		 * @param value
		 *
		 */
		public function set textAlign(value:String):void
		{
			_textAlign=value;
			updateTextField();
		}

		public function get selectAble():Boolean
		{
			return _selectAble;
		}

		public function set selectAble(value:Boolean):void
		{
			_selectAble=value;
			updateTextField();
		}

		public function get type():String
		{
			return _type;
		}

		public function set type(value:String):void
		{
			_type=value;
			updateTextField();
		}

		public function get displayAsPassword():Boolean
		{
			return _displayAsPassword;
		}

		public function set displayAsPassword(value:Boolean):void
		{
			_displayAsPassword=value;
			updateTextField();
		}
	}

}
